<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/vectrics.tld" prefix="vectrics" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>


<%@ page import="org.vectrics.recruiter.config.RecruitConfig" %>
<%@ page import="org.vectrics.recruiter.job.Job" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="org.vectrics.recruiter.config.*" %>
<%@ page import="org.vectrics.recruiter.job.*" %>
<%@ page import="org.vectrics.company.*" %>
<%@ page import="org.vectrics.provider.*" %>

<%@ page import="java.util.*" %>
<%@ page import="org.vectrics.recruiter.struts.admin.AdminJobForm" %>
<%@ page import="org.vectrics.hibernate.*" %>
<%@ page import="org.vectrics.recruiter.*" %>

<jsp:useBean id="adminJobForm" class="org.vectrics.recruiter.struts.admin.AdminJobForm" scope="request"/>

<vectrics:errors debug="false"/>
<%
	boolean autoRefId = RecruitConfig.getRecruitInstance().getAutoJobReferenceId(ThreadProperties.getDomain());
	Logger log = Logger.getLogger(this.getClass());
	
	log.debug("getting params");
	String jobId = request.getParameter("jobId");
	String locationId = null;
	String functionCode = null;
	String companyId = null;
	String domainId = null;
	companyId = (String)request.getAttribute("companyId");


	log.debug("finding job");
	Job job = null;
	if (jobId != null)
		job = RecruitServiceLocator.getJobProvider().findJob(new Long(jobId));
	if (job != null)  {
		log.debug("finding location");
		if (job.getLocation() != null) {
	log.debug("location is not null");
	locationId = job.getLocation().getId().toString();
	if (job.getFunction() != null)
		functionCode = job.getFunction().getCode();
		}
		if (companyId == null) {
	if (job.getCompany() != null) {
		companyId = job.getCompany().getId().toString();
	}
		}
		
	}
	Company company = CoreServiceLocator.getCompanyService().findCompany(new Long(companyId));
	domainId = company.getDomain().getId().toString();
	
	String summary = request.getParameter("summary");
	Boolean canChangeStatus = (Boolean)request.getSession().getAttribute("canChangeStatus");
	Collection notAuthJobStatusTypes = (Collection)request.getSession().getAttribute("jobStatusTypesNotAuth");
	boolean hasNotAuthStatuses = false;
%>


<html:form action="/admin/jobs/save" method="POST" focus="functionCode">
	<html:hidden property="companyId"/>

<% if (jobId != null) {%>
	<input type="hidden" name="jobId" value="<%=jobId%>">
<% } %>

	<table>
		<tr>
			<td valign="TOP">
				<table width="600" cellpadding="4" cellspacing="1">
					<tr>
						<td class="formBg2">
							<font class="stdFont"><bean:message key="prompt.job.company"/></font>
						</td>
						<td class="formBg2">
							<font class="stdFont"><bean:write name="adminJobForm" property="companyName"/></font>
						</td>
					</tr>				
		<% if (autoRefId == false) { %>					
					<tr>
						<td class="formBg1" valign="top">
							<font class="formLabelClass"><bean:message key="prompt.job.reference.id"/></font>
							<vectrics:errors property="referenceId"/>
						</td>
						
						<td class="formBg1" valign="top">
							<html:text property="referenceId" 
									styleClass="formEditClass" maxlength="20"/>
						</td>
					</tr>
		<% } else { %>					
					<tr>
						<td class="formBg1">
							<font class="stdFont"><bean:message key="prompt.job.reference.id"/></font>
						</td>
						<td class="formBg1">
							<font class="stdFont"><bean:write name="adminJobForm" 
									property="referenceId"/></font>
						</td>
					</tr>				
		<% } %>		
					<tr>
						<td class="formBg2" valign="top" width="50%">
							<font class="formLabelClass"><bean:message key="prompt.job.function"/><b> *</b></font>
							<vectrics:errors property="functionCode"/>
						</td>
						<td class="formBg2" valign="top" width="50%">
							<vectrics:jobFunctionCombo property="functionCode"
									 styleClass="formComboClass" value="<%=functionCode%>"/>
						</td>
					</tr>
			

					<tr>
						<td class="formBg1" valign="top">
							<font class="formLabelClass"><bean:message key="prompt.job.title"/><b> *</b></font></td>
						<td class="formBg1" valign="top">
							<html:text property="title" styleClass="formEditClass" maxlength="100"/>
						</td>
					</tr>


					<tr>
						<td class="formBg1" valign="top">
							<font class="formLabelClass"><bean:message key="prompt.job.featured"/></font>
							<vectrics:errors property="featured"/>
						</td>
						<td class="formBg1" valign="top">
							<html:checkbox property="featured"/>
						</td>
					</tr>

					<tr>
						<td class="formBg2" valign="top">
							<font class="formLabelClass"><bean:message key="prompt.job.location"/></font>
						</td>
						<td class="formBg2" valign="top">
							<vectrics:locationCombo 
								property="locationId" 
								locationType="job.location"
								domainId="<%=domainId%>"
								styleClass="formComboClass" 
								selected="<%=locationId%>"/>
						</td>
					</tr>

					<tr>
						<td class="formBg1" valign="top">
							<font class="formLabelClass"><bean:message 
								key="prompt.job.primary.recruiter"/></font>
						</td>
						<td class="formBg1" valign="top">
							<vectrics:recruiterCombo 
								property="primaryRecruiter" 
								styleClass="formComboClass"
								addNoPersonOption="false" 
								companyId="<%=companyId%>"
								jobId="<%=jobId%>"
								/>
						</td>
					</tr>

					<tr>
						<td class="formBg2" valign="top">
							<font 
								class="formLabelClass"><bean:message key="prompt.job.secondary.recruiter"/></font>
						</td>
						<td class="formBg2" valign="top">
							<vectrics:recruiterCombo 
								property="secondaryRecruiter" 
								styleClass="formComboClass" 
								addNoPersonOption="true" 
								companyId="<%=companyId%>"
								jobId="<%=jobId%>"
								/>
						</td>
					</tr>

					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.description"/></font></td>
						<td class="formBg1" valign="top">
							<html:textarea rows="12" property="description" style="font-family:verdana,arial,sans serif;font-size=9px" cols="60" styleClass="formTextAreaClass"/>
						</td>
					</tr>
					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.summary"/></font></td>
						<td class="formBg2" valign="top">
							<html:textarea rows="12" property="summary" style="font-family:verdana,arial,sans serif;font-size=9px" cols="60" styleClass="formTextAreaClass"/>
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.company.information"/></font></td>
						<td class="formBg1" valign="top">
							<html:textarea rows="8" property="companyInfo" style="font-family:verdana,arial,sans serif;font-size=9px" cols="60" styleClass="formTextAreaClass"/>
						</td>
					</tr>

					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.skills"/></font></td>
						<td class="formBg2" valign="top"><html:textarea rows="8" property="requiredSkills" style="font-family:verdana,arial,sans serif;font-size=10px" cols="60" styleClass="formTextAreaClass"/></td>
					</tr>
					
					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.education"/></font></td>
						<td class="formBg1" valign="top"><html:textarea rows="8" property="education" style="font-family:verdana,arial,sans serif;font-size=9px" cols="60" styleClass="formTextAreaClass"/></td>
					</tr>
					
					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.pay.type"/></font></td>
						<td class="formBg2" valign="top">
							<html:select name="adminJobForm" property="payType" styleClass="formComboClass">
							  <html:options collection="jobPayTypes" labelProperty="name" property="code"/>
							</html:select>
						</td>
					</tr>

					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass">
							<bean:message key="prompt.job.classification"/></font>
						</td>
						<td class="formBg2" valign="top">
							<html:select name="adminJobForm" property="classification" styleClass="formComboClass">
							  <html:options collection="jobClassifications" labelProperty="description" property="code"/>
							</html:select>
						</td>
					</tr>


					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.salary.or.min"/></font></td>
						<td class="formBg1" valign="top"><html:text styleClass="formEditClass" property="salary"/></td>
					</tr>
					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.salary.max"/></font></td>
						<td class="formBg2" valign="top"><html:text styleClass="formEditClass" property="salaryMax"/></td>
					</tr>
					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.salary.type"/></font></td>
						<td class="formBg1" valign="top">
							<html:select name="adminJobForm" property="salaryType" styleClass="formComboClass">
							  <html:options collection="jobSalaryTypes" labelProperty="name" property="code"/>
							</html:select>
						</td>
					</tr>

					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.hiring.manager"/></font></td>
						<td class="formBg2" valign="top">
							<html:select 
									name="adminJobForm" 
									property="hiringManager" 
									styleClass="formComboClass">
							  <html:options 
							  		collection="hiringManagers" 
							  		labelProperty="name" 
							  		property="id"/>
							</html:select>
						</td>
					</tr>

					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.work.schedule"/></font></td>
						<td class="formBg1" valign="top">
							<vectrics:workScheduleCombo property="workSchedule" jobId="<%=jobId%>" styleClass="formComboClass"/>
						</td>
					</tr>

					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.terms"/></font></td>
						<td class="formBg2" valign="top">
							<vectrics:termsCombo property="termCode" jobId="<%=jobId%>" styleClass="formComboClass"/>
						</td>
					</tr>
					<tr>
						<td class="formBg1" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.travel"/></font></td>
						<td class="formBg1" valign="top">
							<vectrics:travelCombo styleClass="formComboClass" property="travelPercent" jobId="<%=jobId%>"/>
						</td>
					</tr>
					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.search.words"/></font></td>
						<td class="formBg2" valign="top">
							<html:text styleClass="formEditClass" property="searchWords"/>
						</td>
					</tr>
					<tr>
						<td valign="TOP" align="left"></td>
						<td valign="TOP" align="left">
							<vectrics:formButton elementId="ok.btn" code="button.ok" phraseCode="button.ok" value="submit" name="submit"/>&nbsp;
							<vectrics:formButton elementId="cancel.btn" code="button.cancel" phraseCode="button.cancel" value="cancel" name="cancel"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</html:form>